/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-10 08:50:19
 * @LastEditTime : 2023-05-10 09:05:16
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Pages\Front\Common\Template\GantryCrane.jsx
 * @Description  :
 */
import './Scss/GantryCrane.scss'
import { useState, useEffect } from 'react'
import { useRequest } from 'ahooks'
import { Http } from '../../../../Common/Api'

const WindStateList = { 0: '正常', 1: '初级预警', 2: '中级预警', 3: '高级预警' }

export const GantryCrane001 = () => {
    const [Data, setData] = useState([
        {
            uuid: '1',
            title: '终端名称',
            children: [
                { uuid: '1', title: '', value: '...' },
                { uuid: '2', title: '数据时间', bigTitle: true },
                { uuid: '3', title: '', value: '...' },
            ],
        },
        {
            uuid: '2',
            title: '环境状态 ',
            children: [
                { uuid: '1', title: '风力 :', value: 0, unit: 'm' },
                { uuid: '2', title: '风力状态 :', value: '...' },
                { uuid: '3', title: '主梁角度 :', value: 0, unit: '度' },
            ],
        },
        {
            uuid: '3',
            title: '主钩状态',
            children: [
                { uuid: '1', title: '重量 :', value: 0, unit: 't', state: 0 },
                { uuid: '2', title: '高度 :', value: 0, unit: 'm', state: 0 },
                { uuid: '3', title: '升起速度 :', value: 0, unit: 'm/s', state: 0 },
            ],
        },
        {
            uuid: '4',
            title: '副钩状态 ',
            children: [
                { uuid: '1', title: '重量 :', value: 0, unit: 't', state: 0 },
                { uuid: '2', title: '高度 :', value: 0, unit: 'm', state: 0 },
                { uuid: '3', title: '起升速度 :', value: 0, unit: 'm/s' },
            ],
        },
        {
            uuid: '5',
            title: '大车状态',
            children: [
                { uuid: '1', title: '形成 :', value: 0, unit: 'm', state: 0 },
                { uuid: '2', title: '状态 :', value: '...', state: 0 },
                { uuid: '3', title: '速度 :', value: 0, unit: 'm/s' },
            ],
        },
        {
            uuid: '6',
            title: '小车状态 ',
            children: [
                { uuid: '1', title: '行程 :', value: 0, unit: 'm', state: 0 },
                { uuid: '2', title: '行程2 :', value: '...', unit: 'm', state: 0 },
                { uuid: '3', title: '速度 :', value: 0, unit: 'm/s' },
            ],
        },
    ])
    const { runAsync: getLabGantryCrane } = useRequest(Http, { manual: true })
    const { runAsync: getGantryCrane } = useRequest(Http, {
        manual: true,
        onSuccess: res => {
            const [{ uuid }] = res.list
            getLabGantryCrane({
                url: 'getLabGantryCrane',
                data: { gantryCraneUuid: uuid, pageIndex: 1, pageSize: 1, OrderField: 'createTime@desc' },
            }).then(res => {
                if (res.list === 0) return false
                const [data] = res.list
                if (data || JSON.stringify(data) !== '{}') {
                    setData([
                        {
                            uuid: '1',
                            title: '终端名称',
                            children: [
                                { uuid: '1', title: '', value: data?.equipmentName },
                                { uuid: '2', title: '数据时间', bigTitle: true },
                                { uuid: '3', title: '', value: data?.updateTime },
                            ],
                        },
                        {
                            uuid: '2',
                            title: '环境状态 ',
                            children: [
                                { uuid: '1', title: '风力 :', value: data?.WindSpeed || 0 },
                                { uuid: '2', title: '风力状态 :', value: WindStateList[data?.WindState || 0] },
                                { uuid: '3', title: '主梁角度 :', value: data?.girderAngle || 0, unit: '度' },
                            ],
                        },
                        {
                            uuid: '3',
                            title: '主钩状态',
                            children: [
                                {
                                    uuid: '1',
                                    title: '重量 :',
                                    value: data?.mainWeight || 0,
                                    unit: 't',
                                    state: data?.mainWeightState || 0,
                                },
                                {
                                    uuid: '2',
                                    title: '高度 :',
                                    value: data?.mainHeight || 0,
                                    unit: 'm',
                                    state: data?.mainHeightState || 0,
                                },
                                {
                                    uuid: '3',
                                    title: '升起速度 :',
                                    value: data?.mainSpeed || 0,
                                    unit: 'm/s',
                                    state: data?.mainSpeedState || 0,
                                },
                            ],
                        },
                        {
                            uuid: '4',
                            title: '副钩状态 ',
                            children: [
                                {
                                    uuid: '1',
                                    title: '重量 :',
                                    value: data?.auxWeight || 0,
                                    unit: 't',
                                    state: data?.auxWeightState || 0,
                                },
                                {
                                    uuid: '2',
                                    title: '高度 :',
                                    value: data?.auxHeight || 0,
                                    unit: 'm',
                                    state: data?.auxHeightState || 0,
                                },
                                {
                                    uuid: '3',
                                    title: '起升速度 :',
                                    value: data?.auxSpeed || 0,
                                    unit: 'm/s',
                                    state: data?.auxSpeedState || 0,
                                },
                            ],
                        },
                        {
                            uuid: '5',
                            title: '大车状态',
                            children: [
                                {
                                    uuid: '1',
                                    title: '行程 :',
                                    value: data?.mainDistance || 0,
                                    unit: 'm',
                                    state: data?.mainDistanceState || 0,
                                },
                                { uuid: '2', title: '偏斜 :', value: data?.craneDeflection || 0, unit: '度' },
                                { uuid: '3', title: '速度 :', value: data?.mainCartSpeed || 0, unit: 'm/s' },
                            ],
                        },
                        {
                            uuid: '6',
                            title: '小车状态 ',
                            children: [
                                {
                                    uuid: '1',
                                    title: '行程 :',
                                    value: data?.auxDistance || 0,
                                    unit: 'm',
                                    state: data?.auxDistanceState || 0,
                                },
                                {
                                    uuid: '2',
                                    title: '行程2 :',
                                    value: data?.auxDistance2 || 0,
                                    unit: 'm',
                                    state: data?.auxDistanceState2 || 0,
                                },
                                { uuid: '3', title: '速度 :', value: data?.auxCartSpeed || 0, unit: 'm/s' },
                            ],
                        },
                    ])
                }
            })
        },
    })

    useEffect(() => {
        getGantryCrane({ url: 'getGantryCrane' })
    }, [getGantryCrane])

    return (
        <div className="GantryCrane001">
            {Data.map(({ uuid, title, children }) => (
                <div className="List" key={uuid}>
                    <div className="Title">{title}</div>
                    <div className="Item">
                        {children.map(({ uuid, title, value, unit, state, bigTitle }) => (
                            <div key={uuid}>
                                {title && <div className={bigTitle ? 'bigTitle' : 'Title'}>{title} </div>}
                                <div className="Value">{value}</div>
                                {unit && <div className="Unit">{unit}</div>}
                                {(state || state === 0) && (
                                    <div
                                        className="State"
                                        style={state === 0 ? { color: '#63d650' } : { color: '#EC7351' }}
                                    >
                                        {WindStateList[state]}
                                    </div>
                                )}
                            </div>
                        ))}
                    </div>
                </div>
            ))}
        </div>
    )
}
